package com.ky.manage.activity.outdoor;

import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.ky.manage.R;
import com.ky.manage.adapter.FragmentTabAdapter;
import com.ky.manage.base.BaseActivity;
import com.ky.manage.fragment.OutdoorModifyTabFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 户外整改记录
 */
public class OutdoorMendListActivity extends BaseActivity {


    private List<Fragment> mFragmentList = new ArrayList<>();
    private OutdoorModifyTabFragment allTabFragment, modifiedTabFragment, toModifyTabFragment;

    private ViewPager mPager;
    private RadioGroup mTabRg;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_outdoor_mend_list;
    }

    @Override
    protected void initView() {
        findTextView(R.id.page_title_tv, "户外整改记录");
        findView(R.id.back_iv, v -> {
            finish();
        });
        mTabRg = findView(R.id.tab_rg);
        mTabRg.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.all_tab_rb) {
                mPager.setCurrentItem(0, true);
            } else if (checkedId == R.id.tab_modified_rb) {
                mPager.setCurrentItem(1, true);
            } else if (checkedId == R.id.tab_to_modify_rb) {
                mPager.setCurrentItem(2, true);
            }
        });
        mPager = findView(R.id.view_pager);
        //全部
        allTabFragment = new OutdoorModifyTabFragment();
        //状态（0正常， 1待整改， 2已整改）
        modifiedTabFragment = new OutdoorModifyTabFragment("2");
        toModifyTabFragment = new OutdoorModifyTabFragment("1");
        mFragmentList.add(allTabFragment);
        mFragmentList.add(modifiedTabFragment);
        mFragmentList.add(toModifyTabFragment);

        mPager.setAdapter(new FragmentTabAdapter(getSupportFragmentManager(), mFragmentList));
        mPager.setOffscreenPageLimit(1);
        mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                RadioButton radioButton = (RadioButton) mTabRg.getChildAt(position);
                radioButton.setChecked(true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void initData() {

    }
}